#!/bin/bash -n

[[ -d "$resource_path" ]] && {
    bash.report "Removing old files" rm -rf "$resource_path";
}

bash.report "Initializing installation path" mkdir -p "$resource_path";

registeredFiles='
    core.sh
    ./object
    ttyowner
    b64
    shproc
    bash.generic.error
    bash-executor
    zhtml zinputbox ztextarea zselectfile
';

bash.report "Copying files" cp -r -t $resource_path $registeredFiles;

.src() {

    echo '# This file was automatically generated; Eat at your own risk.';
    echo
    echo '# You may specify an option of -d or --direct-path to cause';
    echo '# modules to be loaded by their full path specification.';

    echo "
    [[ -z \$BASHMASTERS ]] && declare -r BASHMASTERS='${resource_path}';
    "  
    echo -n "$(< 'install/source-handler.tail')";

} >/bin/bash-masters

bash.report "Generating source handler" .src;

bash.report "Creating object links" bash.configure.objects "${resource_path}";

bash.report "Creating user home directory" mkdir -v ~/bash-masters;

bash.io.write -c blue -b -f '\n' += line "The bash-masters are now installed.";

